@import '../style/mixins/index';
@import '../style/theme/color';
@import '../style/theme/corner';

.devui-checkbox {
  position: relative;
  display: flex;
  display: -ms-flexbox;
  align-items: center;
  -ms-flex-align: center;
  height: 100%;
  margin: 0;

  .devui-checkbox-tick {
    position: absolute;

    .devui-tick {
      fill: $devui-light-text;
      stroke-dashoffset: 50;
      opacity: 0;
      transform: scale(0);
      transform-origin: 50% 50%;
      transition: stroke-dashoffset 0.2s ease-in-out, opacity 0.2s ease-in-out, transform 0.2s ease-in-out;
    }
  }

  &.active:not(.halfchecked) .devui-tick {
    opacity: 1;
    stroke-dashoffset: 0;
    transform: scale(1);
    transition: stroke-dashoffset 0.3s cubic-bezier(0.755, 0.05, 0.855, 0.06), opacity 0.2s cubic-bezier(0.755, 0.05, 0.855, 0.06);
  }

  &.active,
  &.halfchecked {
    &:not(.disabled) .devui-checkbox-material:not(.custom-color) {
      border-color: $devui-brand;
    }
  }

  &.active:not(.disabled) {
    .devui-checkbox-material {
      background-size: 100% 100%;
      transition: background-size 0.2s ease-in-out, border-color 0.2s ease-in-out;
    }
  }

  &.unchecked:not(.disabled) {
    .devui-checkbox-material:not(.custom-color) {
      background-size: 0% 0%;
      transition: background-size 0.2s ease-in-out, border-color 0.2s ease-in-out;

      &:hover {
        border-color: $devui-icon-fill-active;
      }
    }
  }

  &.unchecked:not(.disabled) {
    .devui-checkbox-material.custom-color {
      background-size: 0% 0%;
      transition: background-size 0.2s ease-in-out, border-color 0.2s ease-in-out;
    }
  }

  &.halfchecked {
    .devui-checkbox-material:not(.custom-color) {
      background-color: $devui-brand;

      & > .devui-checkbox-halfchecked-bg {
        opacity: 1;
        transform: scale(0.4288);
        transition: transform 0.2s cubic-bezier(0.755, 0.05, 0.855, 0.06);
        background-color: $devui-light-text;
      }
    }
  }

  &.halfchecked {
    .devui-checkbox-material.custom-color {
      & > .devui-checkbox-halfchecked-bg {
        opacity: 1;
        transform: scale(0.4288);
        transition: transform 0.2s cubic-bezier(0.755, 0.05, 0.855, 0.06);
        background-color: $devui-light-text;
      }
    }
  }

  .devui-checkbox-material {
    text-align: initial;
    height: 14px;
    width: 14px;
    position: relative;
    user-select: none;
    border: 1px solid $devui-line;
    border-radius: $devui-border-radius;
    background: linear-gradient($devui-brand, $devui-brand) no-repeat center/0%;
    margin-right: 8px;
    vertical-align: text-bottom;

    &.devui-checkbox-default-background {
      background-color: $devui-base-bg;
    }

    &.devui-checkbox-no-label {
      margin-right: 0;
    }

    & > .devui-checkbox-halfchecked-bg {
      display: inline-block;
      position: absolute;
      content: '';
      background-color: $devui-light-text;
      top: 0;
      left: 0;
      height: 100%;
      width: 100%;
      transform: scale(1);
      opacity: 0;
    }

    & > svg {
      width: 14px;
      height: 14px;
    }
  }

  &:not(.disabled).halfchecked {
    .devui-checkbox-material:not(.custom-color) {
      &:focus,
      &:active,
      &:hover {
        background-color: $devui-icon-fill-active;
      }

      // 激活状态深色
      &:active,
      &:focus,
      &:hover:active,
      &:hover:focus {
        background-color: $devui-brand-active-focus;
      }
    }
  }

  &-input {
    opacity: 0;
    position: absolute;
    margin: 0;
    z-index: -1;
    width: 0;
    height: 0;
    overflow: hidden;
    left: 0;
    pointer-events: none;
  }

  & label {
    position: relative;
    font-weight: normal;
    height: 16px;
    line-height: 16px;
    cursor: pointer;
    color: $devui-text;
    margin: 0;
    display: block;

    & > span {
      display: inline-block;
      box-sizing: content-box;
      vertical-align: top;
    }
  }

  // 禁用状态透明色
  &.disabled {
    label {
      cursor: not-allowed;
      color: $devui-disabled-text;
    }

    .devui-checkbox-material {
      border-color: $devui-icon-fill-active-disabled;
      background-color: $devui-icon-fill-active-disabled;
    }

    &.unchecked {
      .devui-checkbox-material {
        border-color: $devui-disabled-line;
        background-color: $devui-disabled-bg;
      }
    }

    &.halfchecked {
      .devui-checkbox-material {
        background-color: $devui-disabled-bg;

        .devui-checkbox-halfchecked-bg {
          transform: scale(0.4288);
          background-color: $devui-disabled-text;
          opacity: 1;
        }
      }
    }

    &.active {
      svg polygon {
        fill: $devui-light-text;
      }
    }
  }
}

.devui-no-animation {
  transition: none !important;
}
